<%@ page language="java" import="java.util.*" pageEncoding="utf-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
 <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> 
 <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
 <%@ taglib prefix="s" uri="http://www.springframework.org/tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head> 
    <link rel="stylesheet" href="<s:url value="/resources"/>/css/common.css" type="text/css" />   
    <link rel="stylesheet" href="<s:url value="/resources"/>/css/innerstyle.css" type="text/css" />
    <link rel="stylesheet" type="text/css" media="screen" href="<s:url value="/resources"/>/css/cupertino/jquery-ui.custom.min.css" />
	<script type="text/javascript" src="<s:url value="/resources"/>/js/jquery-1.7.2.min.js"></script>
	<script type="text/javascript" src="<s:url value="/resources"/>/js/jquery-ui.custom.min.js"></script> 
	<script type="text/javascript" src="<s:url value="/resources"/>/js/jquery.form.js"></script>
	<script type="text/javascript" src="<s:url value="/resources"/>/js/json2.js"></script>
	<script type="text/javascript" src="<s:url value="/resources"/>/js/jquery.validate.min.js"></script>
	<script type="text/javascript" src="<s:url value="/resources"/>/js/messages_zh.js"></script>
<style type="text/css">
	label.error {  
	        color: red;/*错误信息的颜色*/  
	    }  
	input.error {  
	        border:1px dotted red;/*输入错误的输入框的边框样式*/  
	    }	
</style>
<script type='text/javascript'>
	$(function(){ 
	    $("#but1").button();
	    $("#but2").button(); 
	    $("#but3").button(); 
	    jiaoyan();
	    $( "#dialog-confirm" ).dialog({
            autoOpen: false,            
			resizable: false,
			height:140,
			modal: true,
			buttons: {
				"确认": function() {
				     save();
				},
				"返回": function() {
					$( this ).dialog( "close" );
				}
			}
		});  
		
		//为提交按钮绑定事件
	    $("#but1").click(function () {
             $("#dialog-confirm").dialog("open");
          });
     });
     
      //加载市信息
	     function changForCity(value){ 
	          $.getJSON("<s:url value="/cxtj"/>/changForCity", {province:value}, function(data){
	                  //console.log(data[0]);
	                  // var ret = eval('(' + data[0] + ')'); 
	                  //console.log(ret);
	                  //alert(data[1].regionname); 
	                   $("#city").empty();
	                   $("#city").append("<option value='-1' selected>==请选择==</option>");
			          for(var i=0;i<data.length;i++){
				        sObj = data[i];
				        $("#city").append("<option value='"+sObj.regioncode+"'>"+sObj.regionname+"</option>");
			           } 
	           }); 
	        }
     
   //保存
	function save(){
	  if($("#form1").valid()){ 
	    var url = "<s:url value="/jydz"/>/updateFhdw";
        $("#form1").ajaxSubmit({
             url:url,
             type:'post',
             success:function(data){
              var ret = eval('(' + data + ')');
              alert(ret.msg);
              if(ret.success==true)
              {
                 window.location.href="<s:url value="/jydz"/>/findNewFhdw";
              }
             }		              
        });
        }
	}
	
	//校验
	function jiaoyan()
	{
		    $.validator.addMethod("selectNone", 
	        function(value, element)
	        {   
	            if (value == "-1") 
	            {    
	                return false;    
	            }    
	            else    
	            {   
	                return true;    
	            }   
	        },    
	        "必须选择一项" 
	        ); 
	    
	          $("#form1").validate({
			       rules: {
			       "fahdwmc": "required",
			       "fahdwzs": "required",
			       "faddbr": "required",
			       "suosdq":{ selectNone:true },
			       "hangy":{ selectNone:true }    
			       },
				   messages: {
					   "fahdwmc":"请输入结算单位名称",
				       "fahdwzs":"请输入结算单位住所",
				       "faddbr":"请输入法定代表人",
				       "suosdq":"请选择所属地区",
				       "hangy":"请选择行业"
				       
				   }
			   });
	}
	
	</script>
  </head>
  
 <body>
<div id="best1">
<h2><span>新增发货单位</span></h2>
<form name="form1" id="form1">
<input type="hidden" name="fahdwid" value="${newfhdw[0].fahdwid}" /> 
<table id="list_search" cellpadding="0" cellspacing="0" border="0">
    <tr>
       <td>
          	发货单位名称:<span style="color: red;font-size:16px;vertical-align:middle;">*</span>
          </td>
          <td>
          	<input type="text" name="fahdwmc" class="longtextbox" value="${newfhdw[0].fahdwmc}"/> 
          </td>
      	<td>
          	发货单位住所:<span style="color: red;font-size:16px;vertical-align:middle;">*</span>
          </td>
          <td>
          	<input type="text" name="fahdwzs" class="longtextbox" value="${newfhdw[0].fahdwzs}"/> 
          </td>
          <td>
          	法定代表人:<span style="color: red;font-size:16px;vertical-align:middle;">*</span>
          </td>
          <td>
          	<input type="text" name="faddbr" class="longtextbox" value="${newfhdw[0].faddbr}"/> 
          </td>
       </tr>
       <tr>
          <td>
          	电话:
          </td>
          <td>
          	<input type="text" name="dianh" class="longtextbox" value="${newfhdw[0].dianh}"/> 
          </td>
      	<td>
          	传真:
          </td>
          <td>
          	<input type="text" name="chuanz" class="longtextbox" value="${newfhdw[0].chuanz}"/> 
          </td>
          <td>
          	纳税人登记号:
          </td>
          <td>
          	<input type="text" name="nasrdjh" class="longtextbox" value="${newfhdw[0].nasrdjh}"/> 
          </td>
       </tr>
       <tr>
          <td>
          	邮政编码:
          </td>
          <td>
          	<input type="text" name="youzbm" class="longtextbox" value="${newfhdw[0].youzbm}"/> 
          </td>
      	<td>
          	委托代理人:
          </td>
          <td>
          	<input type="text" name="weitdlr" class="longtextbox" value="${newfhdw[0].weitdlr}"/> 
          </td>
          <td class="pr10 search-table-70">
                                        所属省市:
            </td>
            <td>          	 
        	     <select class="form-textbox" style="width: 93px;" onchange="changForCity(this.value)" >
        	            <option value="-1">==请选择==</option>
						<c:forEach var="province" items="${provincelist}">
							<option value="${province.regioncode}" >${province.regionname}</option>
						</c:forEach>
		           </select>
        	       <select id="city" class="form-textbox" style="width: 93px;" name="suosdq" >
        	            <option value="-1" selected>==请选择==</option>
		            </select>
            </td>
          <%-- <td>
          	所属地区:
          </td>
          <td>
          	<input type="text" name="suosdq" class="longtextbox" value="${newfhdw[0].suosdq}"/> 
          </td> --%>
       </tr>
       <tr>
          <td> 
          	行业:
          </td>
          <td>
          	<div class="select">
					<div>
						<select name="hangy" style="width:180px">
							<c:forEach var="hangy" items="${hangylist}">
								<option value="${hangy.diccode}" <c:if test="${hangy.diccode==newfhdw[0].hangy}">selected="selected"</c:if>>${hangy.dicname}</option>
							</c:forEach>
						</select>
					</div>
			</div>
          </td>
       </tr>
       <%-- <tr>
          <td> 
          	行业:
          </td>
          <td>
          	<input type="text" name="hangy" class="longtextbox" value="${newfhdw[0].hangy}"/> 
          </td>
       </tr>  --%>   
        <tr>
		    <td colspan="6" align="center">	
		            <input id="but1" type="button" value="保存" />&nbsp;&nbsp;&nbsp;
			        <input id="but2" type="reset" value="重置" "/>&nbsp;&nbsp;&nbsp;
			        <input id="but3" type="button" name="" value="返回" onclick="javascript:history.back();"/>
		    </td>
        </tr>
  </table> 
</form>
</div> 
<div id="dialog-confirm" title="是否确认保存？"></div>
  </body>
</html>
